var n = getApp();

require("../../utils/util.js");

Page({
    data: {},
    onLoad: function(n) {},
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    refreshUserProfile: function() {
        n.getRequest(n.globalData.BASE_URL + "/auth/profile", {}).then(function(o) {
            console.log("userInfo", o), n.globalData.userInfo = o, wx.setStorageSync("userInfo", o), 
            n.globalData.campaign && n.campaignEventLog("signin");
        });
    },
    quickLogin: function(o) {
        var e = this, t = n.globalData.code;
        n.postRequest(n.globalData.BASE_URL + "/auth/wx/checkin", {
            js_code: t
        }).then(function(t) {
            n.globalData.token = t.token, n.postRequest(n.globalData.BASE_URL + "/auth/wx/mobile", {
                encryptedData: o.detail.encryptedData,
                vi: o.detail.iv
            }).then(function(o) {
                console.log("quickLogin success", o), n.globalData.token = o.token, n.globalData.userId = o.user_id, 
                wx.setStorageSync("token", o.token), wx.setStorageSync("userId", o.user_id), e.refreshUserProfile(), 
                wx.reLaunch({
                    url: "/pages/stores/stores",
                    success: function(n) {},
                    fail: function(n) {},
                    complete: function(n) {}
                });
            }, function(o) {
                n.showErrorMsg("", "微信登录失败，请重试。"), setTimeout(function() {
                    wx.reLaunch({
                        url: "/pages/stores/stores",
                        success: function(n) {},
                        fail: function(n) {},
                        complete: function(n) {}
                    });
                }, 2e3);
            });
        });
    },
    loginByPhone: function() {
        wx.navigateTo({
            url: "/pages/login-by-phone/login-by-phone",
            success: function(n) {},
            fail: function(n) {},
            complete: function(n) {}
        });
    }
});